import { request,BASEURL } from "../utils/request.js"

// 获取验证码
export const sendCode = tel =>{
	return request({
		url:`/business/sendSms/${tel}`
	})
}

//登录
export const login = (tel,code) =>{
	return request({
		url:`/business/checkCode/${tel}/${code}`
	})
}

//获取完整信息
export const getUserInfo = tel =>{
	return request({
		url:`/business/getUserInfo/${tel}`
	})
}

//获取手机分类
export const getPhone = (limit=1000,page=1,model='') =>{
	return request({
		url:`/config/phoneTypeList?limit=${limit}&page=${page}&model=${model}`
	})
}

//获取轮播图
export const getSwper = (limit=10,page=1,type=1)=>{
	return request({
		url:'/config/bannerList',
		data:{
			limit,
			page,
			type
		}
	})
}

//选择图片
export const selectImage = ()=>{
	return new Promise(reolve =>{
		uni.chooseImage({
			count:1,
			success:({tempFilePaths})=>{
				reolve(tempFilePaths[0])
			},
			fail:()=>{
				uni.hideLoading()
			}
		})
	})
}

//上传图片
export const udpImage =  async ()=>{
	const filePath =  await selectImage()
	return new Promise(reolve=>{
		uni.uploadFile({
			url:`${BASEURL}/config/upload-file`,
			name:"files",
			filePath,
			header:{
				'content-type': 'multipart/form-data'
			},
			success:({data}) =>{
				reolve(data)
			}
		})
	})
}

// 更新微信收款码接口
export const udpnewImage = data =>{
	return request({
		url:'/business/updWxPay',
		method:'POST',
		data
	})
}

// 当前时间格式的转换
export const currentTime = ()=> {
	return new Promise(resolve => {
		var timestamp = Date.parse(new Date());
		timestamp = timestamp / 1000;
		//获取当前时间
		var n = timestamp * 1000;
		var date = new Date(n);
		//年
		var Y = date.getFullYear();
		//⽉
		var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1);
		//⽇
		var D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
		//时
		var h = date.getHours() < 10 ? '0' + date.getHours() : date.getHours();;
		//分
		var m = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes();;
		// 秒 
		var s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
		const currenttime = Y + "-" +M +"-"+D +" "+h +":"+m +":" +s
		resolve(currenttime)
	})
}

// 提交订单
export const submitOrder = data =>{
	return request({
		url:'/business/addOrder',
		method:'POST',
		data
	})
}

//获得订单
export const getOrder = data=>{
	return request({
		url:'/business/staffIdInquiryList',
		data
	})
}

// 待报价点击取消
export const baojiaquxiao = data =>{
	return request({
		url:'/business/toToQuote',
		method:'POST',
		data
	})
}

// 待付款点击取消
export const fukuanquxiao = data =>{
	return request({
		url:'/business/toBeConfirmedCancel',
		method:'POST',
		data
	})
}

// 待发货点击取消
export const fahuoquxiao = data =>{
	return request({
		url:'/business/logisticsCancel',
		method:'POST',
		data
	})
}

// 待确认点击拒绝
export const querquxiao = data =>{
	return request({
		url:'/business/refuseCancel',
		method:'POST',
		data
	})
}

//获取站点信息
export const getzhandian = (limit=1000,page=1)=>{
	return request({
		url:'/config/websiteList',
		data:{
			limit,
			page
		}
	})
}

//提交待确认信息邮寄
export const addQuren = data =>{
	return request({
		url:'/business/affirm',
		method:'POST',
		data
	})
}

//到店发货
export const addStore = data =>{
	return request({
		url:'/business/logisticsReachTheStore',
		method:'POST',
		data
	})
}

//代发货邮寄发货
export const youjiFahuo = data =>{
	return request({
		url:'/business/logistics',
		method:'POST',
		data
	})
}

// 根据订单id 获取订单详情
export const getXiangQin = (orderId)=>{
	return request({
		url:`/business/orderIdInquiry/${orderId}`
	})
}


// 批量发货
export const allfahuo = data =>{
	return request({
		url:'/business/updateLogistics',
		data
	})
}